package com.trgis.yhmap.util.wmtsproxy;


import org.dom4j.DocumentException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.core.io.ClassPathResource;

import javax.annotation.PostConstruct;
import java.io.IOException;

/**
 * @author wangfy
 */
@Scope
public class WMTSProxyConfiguration {
    private static final Logger log = LoggerFactory.getLogger(WMTSProxyConfiguration.class);

    private WmtsXMLReader wmtsXMLReader = WmtsXMLReader.getReader();

    @PostConstruct
    public void refresh(){
        ClassPathResource resource = new ClassPathResource("wmtsCon.xml");
        if(!resource.exists()) {
            log.info("没有找到wmtsCon.xml配置文件");
            return;
        }

        // 读取配置文件
        wmtsXMLReader = WmtsXMLReader.getReader();
        try {
            wmtsXMLReader.readConfig(resource.getFile());
            log.info("wmts 服务代理配置文件读取完成");
        } catch (DocumentException e) {
            log.info("读取配置文件出错");
            wmtsXMLReader = null;
            e.printStackTrace();
        } catch (IOException e) {
            log.info("读取配置文件出错");
            wmtsXMLReader = null;
            e.printStackTrace();
        }
    }
}
